package com.fingard.dsp.bank.directbank.fngrd01;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.directbank.bankInterface.IBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.detail.RetAtsBatPayRecDetail;
import com.fingard.net.ConnState;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

public class FnGrd01BatPayRec extends FnGrd01Base implements IBatPayRec {
	//1988
	public RetAtsBatPayRec d_1988_BatPay(ReqBatPayRec p_req1988) throws Exception{
		return d_BatPayRec(p_req1988);
	}
	//9188
	public RetAtsBatPayRec d_9188_BatPay(ReqBatPayRec p_req9188) throws Exception{
		return d_BatPayRec(p_req9188);
	}
	
	//批量代收和批量代付提交
	public RetAtsBatPayRec d_BatPayRec(ReqBatPayRec p_reqBat) throws Exception{
		//返回ATS的对象
		RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_reqBat.reqHeader);
		try {
			FnGrd01Header bankHeader = new FnGrd01Header();
			
			if(p_reqBat.reqHeader.transType.equals("1988")){
				if(p_reqBat.reqHeader.commandCode.equals("198801")){//批量同行代付
					bankHeader.CommandCode = "11220";
				}
				else if(p_reqBat.reqHeader.commandCode.equals("198802")){//198802', '人行大小额跨行付
					bankHeader.CommandCode = "12228";
				}
				else if(p_reqBat.reqHeader.commandCode.equals("198803")){//198803', '人行大额跨行付
					bankHeader.CommandCode = "12227";
				}
				else if(p_reqBat.reqHeader.commandCode.equals("198804")){//'198804', '人行网银互联跨行付'
					bankHeader.CommandCode = "12229";
				}
				else if(p_reqBat.reqHeader.commandCode.equals("198805")){//'198805', '综合付
					bankHeader.CommandCode = "10220";
				}
				else if(p_reqBat.reqHeader.commandCode.equals("198806")){//'198806', '银联跨行付
					bankHeader.CommandCode = "12225";
				}
			}
			else if(p_reqBat.reqHeader.transType.equals("9188")){
				if(p_reqBat.reqHeader.commandCode.equals("918801")){//11210：批量同行代收
					bankHeader.CommandCode = "11210";
				}else if(p_reqBat.reqHeader.commandCode.equals("918802")){//918802', '跨行收
					bankHeader.CommandCode = "12215";//12215：批量跨行银联收
				}else if(p_reqBat.reqHeader.commandCode.equals("918805")){//918805', '综合代收
					bankHeader.CommandCode = "10210";//10210：综合代收
				}else if("9188Cntr".equals(p_reqBat.reqHeader.commandCode)){
					bankHeader.CommandCode = "112G0";//112G0：批量同行签约代收
				}
			}
			
			bankHeader.CorpBankCode = getBankConfig().getMapValueByKey("corBankCodeMapping", p_reqBat.ownAct);
			if(StringHelper.isNullOrEmpty(bankHeader.CorpBankCode)){
				WriteBankLogLn2("CorpBankCode为空，请配置corBankCodeMapping映射");
			}
			
			if(StringHelper.isNullOrEmpty(this.reqHeader.syBank)){
				this.reqHeader.syBank = bankHeader.CorpBankCode;
	    	}
			
			bankHeader.TransSeqID = getQryTransID();
			bankHeader.SourceChannel = "";
			
			XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
			writeCommonHeader(xmlWriter, bankHeader);
			xmlWriter.writeStartElement("TransReq");
			xmlWriter.writeElementString("TotalNum", p_reqBat.totalNum);
			xmlWriter.writeElementString("TotalAmt", p_reqBat.totalAmt);
			xmlWriter.writeElementString("ReqSeqID", p_reqBat.reqBatchNO);
			xmlWriter.writeElementString("AccountingFlag", "2");
			xmlWriter.writeStartElement("CorpToBank");
			xmlWriter.writeElementString("EncryptFlag", "1");
			xmlWriter.writeElementClosed("SourceDataMD5");
			xmlWriter.writeElementClosed("SourceTotalAmount");
			xmlWriter.writeEndElement();
			xmlWriter.writeStartElement("TransParam");
			if(p_reqBat.reqHeader.transType.equals("1988")){
				xmlWriter.writeElementString("PayAct", p_reqBat.ownAct);
				xmlWriter.writeElementString("PayArea", p_reqBat.ownArea);
				xmlWriter.writeElementString("PayAreaName", p_reqBat.ownAreaName);
			}
			else if(p_reqBat.reqHeader.transType.equals("9188")){
				xmlWriter.writeElementString("RecAct", p_reqBat.ownAct);
				xmlWriter.writeElementString("RecArea", p_reqBat.ownArea);
				xmlWriter.writeElementString("RecAreaName", p_reqBat.ownAreaName);
			}
			xmlWriter.writeElementString("CorpBankCode", bankHeader.CorpBankCode);
			//需要进行对账码拼接以及节点解析，采用XElement进行处理
			while(p_reqBat.readRecord()){
				XElement tmpXElement = new XElement("DetailRecord","");
				
				
					tmpXElement.addChild(new XElement("PayName",p_reqBat.readedDetail.payName));
					tmpXElement.addChild(new XElement("PayAct",p_reqBat.readedDetail.payAct));
					if(p_reqBat.reqHeader.transType.equals("1988")){
						tmpXElement.addChild(new XElement("PayBnk",p_reqBat.readedDetail.payBankLocation));
					}
					else if(p_reqBat.reqHeader.transType.equals("9188")){
						tmpXElement.addChild(new XElement("PayBnk",p_reqBat.readedDetail.getOppBankLocation()));
					}
					tmpXElement.addChild(new XElement("PayArea",p_reqBat.readedDetail.payArea));
					tmpXElement.addChild(new XElement("PayBankCode",p_reqBat.readedDetail.payBankCode));
					tmpXElement.addChild(new XElement("PayBankName",p_reqBat.readedDetail.payBankName));
					tmpXElement.addChild(new XElement("PayAreaName",p_reqBat.readedDetail.payAreaName));						
					
					tmpXElement.addChild(new XElement("RecName",p_reqBat.readedDetail.recName));
					tmpXElement.addChild(new XElement("RecAct",p_reqBat.readedDetail.recAct));
					if(p_reqBat.reqHeader.transType.equals("1988")){
						tmpXElement.addChild(new XElement("RecBnk",p_reqBat.readedDetail.getOppBankLocation()));
					}
					else if(p_reqBat.reqHeader.transType.equals("9188")){
						tmpXElement.addChild(new XElement("RecBnk",p_reqBat.readedDetail.recBankLocation));
					}
					tmpXElement.addChild(new XElement("RecBankCode",p_reqBat.readedDetail.recBankCode));
					tmpXElement.addChild(new XElement("RecBankName",p_reqBat.readedDetail.recBankName));
					tmpXElement.addChild(new XElement("RecArea",p_reqBat.readedDetail.recArea));
					tmpXElement.addChild(new XElement("RecAreaName",p_reqBat.readedDetail.recAreaName));
					
				
				//卡折标记0卡;1折
				if(p_reqBat.readedDetail.cardType.equals("1")){
					tmpXElement.addChild(new XElement("CardType", "1"));
				}
				else{
					tmpXElement.addChild(new XElement("CardType", "0"));
				}
				tmpXElement.addChild(new XElement("SameCity",p_reqBat.readedDetail.sameCity));
				tmpXElement.addChild(new XElement("SameBnk",p_reqBat.readedDetail.sameBnk));
				tmpXElement.addChild(new XElement("PayDate",p_reqBat.readedDetail.payDate));
				tmpXElement.addChild(new XElement("PayTime",p_reqBat.readedDetail.payTime));
				tmpXElement.addChild(new XElement("PayAmount",p_reqBat.readedDetail.payAmount));
				tmpXElement.addChild(new XElement("PayCur", convertCurToBank(p_reqBat.readedDetail.payCur)));
				tmpXElement.addChild(new XElement("RecCur", convertCurToBank(p_reqBat.readedDetail.recCur)));
				tmpXElement.addChild(new XElement("CertType",convertCertTypeToBank(p_reqBat.readedDetail.certType)));
				tmpXElement.addChild(new XElement("CertNum",p_reqBat.readedDetail.certNum));
				tmpXElement.addChild(new XElement("CreditCardSecCode", ""));
				tmpXElement.addChild(new XElement("CreditCardValidity",""));
				if(StringHelper.hasAnyChar(p_reqBat.readedDetail.purpose)){
					tmpXElement.addChild(new XElement("Usage",p_reqBat.readedDetail.purpose));
				}
				else{
					tmpXElement.addChild(new XElement("Usage",p_reqBat.readedDetail.useType));
				}
				tmpXElement.addChild(new XElement("PostScript",p_reqBat.readedDetail.askNumber));
				tmpXElement.addChild(new XElement("Memo",p_reqBat.readedDetail.memo));
				tmpXElement.addChild(new XElement("ReqReserve",p_reqBat.readedDetail.abstractATS));
				tmpXElement.addChild(new XElement("CNAPSCode",p_reqBat.readedDetail.cnapsCode));
				tmpXElement.addChild(new XElement("CNAPSName",p_reqBat.readedDetail.cnapsName));
				if(p_reqBat.readedDetail.isPrivate.equals("1")){//0：私人   1：公司
					tmpXElement.addChild(new XElement("IsPrivate","0"));
				}
				else{
					tmpXElement.addChild(new XElement("IsPrivate","1"));
				}
				tmpXElement.addChild(new XElement("SourceNote",p_reqBat.readedDetail.sourceNote));
				//PolicyNumber 投保单号或者保单号直接扣款非必填，签约扣款必填，需要和签约接口中填一样
				String tmpPolicyNumber = StringHelper.getFirstNotEmpty(p_reqBat.readedDetail.insuPolicyNum,p_reqBat.readedDetail.sourceNoteCode);
				tmpXElement.addChild(new XElement("PolicyNumber", tmpPolicyNumber));
				String agreementNo = "";
				String[] authCodeSp = p_reqBat.readedDetail.authCode.split("__");
				String protocolCode = authCodeSp[0];
				if(authCodeSp.length>1){
					agreementNo = authCodeSp[1];
				}
				tmpXElement.addChild(new XElement("ProtocolCode", protocolCode));
				tmpXElement.addChild(new XElement("AgreementNo", agreementNo));//"010AD091011911146384987"
				nodeAnalysis(p_reqBat.readedDetail.srcXElement, tmpXElement, getCharset());
				xmlWriter.writeXElement(tmpXElement);
			}
			xmlWriter.writeEndDocument();//写入报文完成
			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());//发送银行
			if(tmpStrRet[0].length() == 0){
				StringBuilder tmpSbMsg = new StringBuilder();
				//解析银行返回
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if(tmpBkReader != null){
					String tmpRetCode = tmpBkReader.getFirstText("/Root/Head/RespCode");
					String tmpRetMsg = tmpBkReader.getFirstText("/Root/Head/RespInfo");
					int tmpIntRespCode = -1;
					if(!StringHelper.isNullOrEmpty(tmpRetCode)){
	                    tmpIntRespCode = Integer.parseInt(tmpRetCode);
	                }
	                if (tmpIntRespCode >= 0){
	                	retAts.respCode = "0";
						retAts.respInfo = tmpRetMsg;
						retAts.reqSeqID = tmpBkReader.getFirstText("/Root/TransResp/ReqSeqID");
						retAts.transState = tmpBkReader.getFirstText("/Root/TransResp/TransState");
						retAts.payInfoCode = tmpBkReader.getFirstText("/Root/TransResp/PayInfoCode");

						String payStatus = tmpBkReader.getFirstText("/Root/TransResp/TransState");
						if ("4".equals(payStatus) && "308".equals(bankHeader.CorpBankCode) && p_reqBat.reqHeader.isFromSinglePay) {
                            long realSleepTime = getBankConfig().getValueAsInt("realSleepTime");
                            Thread.sleep(realSleepTime*1000);

							bankHeader = new FnGrd01Header();
							bankHeader.CommandCode = "21210";
							bankHeader.TransSeqID = getQryTransID();
							bankHeader.SourceChannel = "";

							xmlWriter = new XmlTextWriter();//发银行报文的XML对象
							writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
							xmlWriter.writeStartElement("TransReq");
							xmlWriter.writeElementString("ReqSeqID", p_reqBat.reqBatchNO);
							xmlWriter.writeElementString("BgnDate", Format.Date10Format.format(p_reqBat.getPayDateTime()));
							xmlWriter.writeElementString("RecAct", p_reqBat.ownAct);
							xmlWriter.writeElementString("RecArea", "");
							xmlWriter.writeElementString("TotalNum", "1");
							xmlWriter.writeElementString("TotalAmount", p_reqBat.totalAmt);
							xmlWriter.writeStartElement("CorpToBank");
							xmlWriter.writeElementString("EncryptFlag", "1");
							xmlWriter.writeEndElement();
							xmlWriter.writeEndDocument();

							tmpStrRet = sendToBank(xmlWriter.toXmlString());
							if(tmpStrRet[0].length() == 0){
								tmpSbMsg = new StringBuilder();
								tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
								if(tmpBkReader != null){
									tmpRetCode = tmpBkReader.getFirstText("/Root/Head/RespCode");
									tmpRetMsg = tmpBkReader.getFirstText("/Root/Head/RespInfo");
									tmpIntRespCode = -1;
									if(!StringHelper.isNullOrEmpty(tmpRetCode)){
										tmpIntRespCode = Integer.parseInt(tmpRetCode);
									}
									if (tmpIntRespCode >= 0){
										retAts.respCode = "0";
										retAts.reqSeqID = tmpBkReader.getFirstText("/Root/TransResp/ReqSeqID");
										String transState = tmpBkReader.getFirstText("/Root/TransResp/TransState");
										boolean isBatFailed = false;
										if("3".equals(transState)){
											retAts.transState = transState;
											retAts.payInfoCode = tmpBkReader.getFirstText("/Root/TransResp/PayInfoCode");
											retAts.respInfo = tmpRetMsg;
											if(tmpBkReader.countElement("/Root/TransResp/DetailRecord")==1){
												isBatFailed = true;
											}
										}

										while(tmpBkReader.read("/Root/TransResp/DetailRecord")){
											retAts.transState = tmpBkReader.readedXElement.getSingleText("Result");
											retAts.payInfoCode = tmpBkReader.readedXElement.getSingleText("PayInfoCode");
											retAts.reqSeqID = tmpBkReader.readedXElement.getSingleText("PostScript");
											retAts.respInfo = tmpBkReader.readedXElement.getSingleText("Memo");
											return retAts;
										}
									}
									else{
										retAts.respCode = "-1";
										retAts.respInfo = tmpRetMsg;
									}
								}
								else{
									retAts.respCode = "-1";
									retAts.respInfo = tmpSbMsg.toString();
								}
							}
							else{
								retAts.respCode = "-1";
								retAts.respInfo = tmpStrRet[1];
							}
						}
	                }
	                else{
	                	retAts.respCode = "-1";
	                	if (StringHelper.isNullOrEmpty(tmpRetMsg))
	                    {
	                		retAts.respInfo = "前置返回查询失败RespCode：" + tmpRetCode;
	                    }
	                    else
	                    {
	                    	retAts.respInfo = tmpRetMsg;
	                    }
	                }
				}
				else{
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
			}
			else if(tmpStrRet[0].equals(ConnState.FAIL)){
				retAts.respCode = "0";
				retAts.respInfo = tmpStrRet[1];
				retAts.reqSeqID = p_reqBat.reqBatchNO;
				retAts.transState = PaymentState.FAIL_Batch;
				retAts.payInfoCode = tmpStrRet[0];
			}
			else{
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}
			
		}catch (Exception e) {
			retAts.respCode = "-1";
			retAts.respInfo = e.toString();
			this.WriteBankLogLn(e);
		}
		if(retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)){
			retAts.reqSeqID = p_reqBat.reqBatchNO;
		}
		retAts.writeRetToATS();
		return retAts;
	}

	//1998 状态查询
	public RetAtsQryBatPayRec d_1998_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception{
		return d_QryBatPayRec(p_req1998);
	}
	//9198
	public RetAtsQryBatPayRec d_9198_QryBatPay(ReqQryBatPayRec p_req9198) throws Exception{
		return d_QryBatPayRec(p_req9198);
	}
	
	//批量代收和批量代付状态查询
	public RetAtsQryBatPayRec d_QryBatPayRec(ReqQryBatPayRec p_reqQryBat) throws Exception{
		//返回ATS的对象
		RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_reqQryBat.reqHeader);
		retAts.respCode = "";
		
		FnGrd01Header bankHeader = new FnGrd01Header();
		if(p_reqQryBat.reqHeader.transType.equals("1998")){
			if(p_reqQryBat.reqHeader.commandCode.equals("198801")){
				bankHeader.CommandCode = "21220";
			}
			else if(p_reqQryBat.reqHeader.commandCode.equals("198802")){//198802', '人行大小额跨行付
				bankHeader.CommandCode = "22228";
			}
			else if(p_reqQryBat.reqHeader.commandCode.equals("198803")){//198803', '人行大额跨行付
				bankHeader.CommandCode = "22227";
			}
			else if(p_reqQryBat.reqHeader.commandCode.equals("198804")){//'198804', '人行网银互联跨行付'
				bankHeader.CommandCode = "22229";
			}
			else if(p_reqQryBat.reqHeader.commandCode.equals("198805")){//'198805', '综合付
				bankHeader.CommandCode = "20220";
			}
			else if(p_reqQryBat.reqHeader.commandCode.equals("198806")){//'198806', '银联跨行付
				bankHeader.CommandCode = "22225";
			}
		}
		else if(p_reqQryBat.reqHeader.transType.equals("9198")){
			if(p_reqQryBat.reqHeader.commandCode.equals("918801")){
				bankHeader.CommandCode = "21210";
			}else if(p_reqQryBat.reqHeader.commandCode.equals("918802")){//918802', '跨行收
				bankHeader.CommandCode = "22215";
			}else if(p_reqQryBat.reqHeader.commandCode.equals("918805")){//918805', '综合代收
				bankHeader.CommandCode = "20210";//20210：综合代收查询
			}else if("9188Cntr".equals(p_reqQryBat.reqHeader.commandCode)){
				bankHeader.CommandCode = "212G0";//212G0：批量同行签约代收查询
			}
		}
		
		bankHeader.CorpBankCode = getBankConfig().getMapValueByKey("corBankCodeMapping", p_reqQryBat.ownAct);
		if(StringHelper.isNullOrEmpty(bankHeader.CorpBankCode)) {
			WriteBankLogLn2("CorpBankCode为空，请配置corBankCodeMapping映射");
		}
		
		bankHeader.TransSeqID = getQryTransID();
		bankHeader.SourceChannel = "";
		
		XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
		writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
		xmlWriter.writeStartElement("TransReq");
		xmlWriter.writeElementString("ReqSeqID", p_reqQryBat.reqBatchNO);
		xmlWriter.writeElementString("BgnDate", p_reqQryBat.bgnDate);
		if(p_reqQryBat.reqHeader.transType.equals("1998")){
			xmlWriter.writeElementString("PayAct", p_reqQryBat.ownAct);
			xmlWriter.writeElementString("PayArea", p_reqQryBat.ownArea);	
		}
		else if(p_reqQryBat.reqHeader.transType.equals("9198")){
			xmlWriter.writeElementString("RecAct", p_reqQryBat.ownAct);
			xmlWriter.writeElementString("RecArea", p_reqQryBat.ownArea);
		}
		xmlWriter.writeElementString("TotalNum", p_reqQryBat.totalNum);
		xmlWriter.writeElementString("TotalAmount", p_reqQryBat.totalAmt);
		xmlWriter.writeStartElement("CorpToBank");
		xmlWriter.writeElementString("EncryptFlag", "1");
		xmlWriter.writeEndElement();
		xmlWriter.writeEndDocument();
		try{
			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
			if(tmpStrRet[0].length() == 0){
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if(tmpBkReader != null){
					String tmpRetCode = tmpBkReader.getFirstText("/Root/Head/RespCode");
					String tmpRetMsg = tmpBkReader.getFirstText("/Root/Head/RespInfo");
					int tmpIntRespCode = -1;
					if(!StringHelper.isNullOrEmpty(tmpRetCode)){
	                    tmpIntRespCode = Integer.parseInt(tmpRetCode);
	                }
	                if (tmpIntRespCode >= 0){
						retAts.respCode = "0";
						retAts.reqSeqID = tmpBkReader.getFirstText("/Root/TransResp/ReqSeqID");
						String transState = tmpBkReader.getFirstText("/Root/TransResp/TransState");
						boolean isBatFailed = false;
						if("3".equals(transState)){
							retAts.transState = transState;
							retAts.payInfoCode = tmpBkReader.getFirstText("/Root/TransResp/PayInfoCode");
							retAts.respInfo = tmpRetMsg;
							if(tmpBkReader.countElement("/Root/TransResp/DetailRecord")==1){
								isBatFailed = true;
							}
						}
						retAts.writeBeforeDetail();
						
						while(tmpBkReader.read("/Root/TransResp/DetailRecord")){
							RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
							if(p_reqQryBat.reqHeader.transType.equals("1998")){
								tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("RecAct");
								tmpRetDetail.recName = tmpBkReader.readedXElement.getSingleText("RecName");
							}
							else if(p_reqQryBat.reqHeader.transType.equals("9198")){
								tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("PayAct");
								tmpRetDetail.payName = tmpBkReader.readedXElement.getSingleText("PayName");
							}
							tmpRetDetail.payAmount = tmpBkReader.readedXElement.getSingleText("PayAmount");
							tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("PostScript");
							tmpRetDetail.result = tmpBkReader.readedXElement.getSingleText("Result");
							tmpRetDetail.memo = tmpBkReader.readedXElement.getSingleText("Memo");
							
							tmpRetDetail.payInfoCode = tmpBkReader.readedXElement.getSingleText("PayInfoCode");
							
							String newPayInfoCode = getBankConfig().getMapIncludeValue("payInfoCodeMapping", tmpRetDetail.memo);
							if(StringHelper.hasAnyChar(newPayInfoCode)){
								tmpRetDetail.payInfoCode = newPayInfoCode;
							}
							
                            if(isBatFailed && StringHelper.isNullOrEmpty(tmpRetDetail.postScript)){
                            	continue;//整批失败，不写明细节点
                            }else{
                            	retAts.writeRetDetail(tmpRetDetail);
                            }
						}
					}
					else{
						retAts.respCode = "-1";
						retAts.respInfo = tmpRetMsg;
					}
				}
				else{
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
			}
			else{
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}
		}
		catch (Exception e) {
			retAts.respCode = "-1";
			retAts.respInfo = e.getMessage();
			e.printStackTrace();
		}
		if(retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)){
			retAts.reqSeqID = p_reqQryBat.reqBatchNO;
		}
		if(retAts.respCode.equals("-1")){
			retAts.writeBeforeDetail();
		}
		retAts.writeAfterDetail();
		return retAts;
	}	
}
